package com.alameda.controller.v1.user;

import com.alameda.common.result.Result;
import com.alameda.service.user.AdUserOrganizationService;
import com.alameda.service.user.AdUserService;
import com.alameda.user.dto.AdUserDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户 前端控制层
 *
 * @author Lv
 * @date 2024/06/02
 */
@Api(tags = "用户")
@RestController
@RequestMapping("/ad_user")
public class AdUserController {

    @Autowired
    private AdUserService adUserService;

    /**
     * 获取当前登录用户信息
     *
     * @return
     */
    @ApiOperation("获取当前登录用户信息")
    @PostMapping("/get_user_info")
    public Result<?> getUserInfo() {
        return Result.success(adUserService.getUserInfo());
    }

    /**
     * 修改用户信息
     *
     * @param adUserDTO 用户信息
     * @return
     */
    @ApiOperation("修改用户信息")
    @PostMapping("/edit")
    public Result<?> edit(@RequestBody AdUserDTO adUserDTO) {
        return Result.success(adUserService.edit(adUserDTO));
    }

    /**
     * 查询用户列表
     *
     * @param adUserDTO 用户信息
     * @return
     */
    @ApiOperation("查询用户列表")
    @PostMapping("/load_user")
    public Result<?> loadUser(@RequestBody AdUserDTO adUserDTO) {
        return Result.success(adUserService.loadUser(adUserDTO));
    }

    @Autowired
    private AdUserOrganizationService adUserOrganizationService;

    /**
     * 加载所有子组织下拉框
     *
     * @return
     */
    @ApiOperation("加载所有子组织下拉框")
    @PostMapping("/load_all_son_organization")
    public Result<?> loadAllSonOrganization() {
        return Result.success(adUserOrganizationService.loadAllSonOrganization());
    }

    /**
     * 导出excel
     *
     * @param adUserDTO 用户信息
     */
    @PostMapping("/export")
    public void export(@RequestBody AdUserDTO adUserDTO) {
        adUserService.export(adUserDTO);
    }
}